<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>axios入门与源码解析</title>
  <link rel="stylesheet" href="../bootstrap.min.css">
  <script src="../axios.js"></script>
</head>

<body>
  <div class="container">
    <h2>axios基本使用</h2>
    <p>
      <a href="https://github.com/axios/axios">去Git学习axios</a>
    </p>
    <button class="btn btn-primary">发送GET请求</button>
    <button class="btn btn-warning">发送POST请求</button>
  </div>
  <script>
    // 获取按钮
    const btns = document.querySelectorAll('button')
    // 创建实例对象
    const duanzi = axios.create({
      baseURL:'http://localhost:3000',
      timeout:2000
    })
    // 这里duanzi对象与axios对象几乎一样
    // duanzi({
    //   url:'/comments'
    // }).then(res=>{
    //   console.log(res.data)
    // })
    duanzi.get('/comments').then(res=>{
      console.log(res.data)
    })
  </script>
</body>

</html>